package swa23.provider.impl;
 
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
//import swa2012.telco.broker.beans.Client;
import swa2012.telco.broker.beans.Message;
import swa23.provider.interfaces.MessageRepository;
//import swa2012.telco.sp.MessageRepository;
 
public class MessageRepositoryImpl implements MessageRepository {
	private final Map<String, Set<Message>> messageRepository = new ConcurrentHashMap();
 
	public void addMessage(Message msg) {
		String clientID = msg.getReceiver().getID();
		
		if ((clientID == null) || (clientID.isEmpty())) {
			return;
		}
		if (!this.messageRepository.containsKey(clientID)) {
			this.messageRepository.put(clientID, new HashSet());
		}
		((Set)this.messageRepository.get(clientID)).add(msg);
		}
 
	public Collection<Message> getMessages(String clientID) {
		Collection messages = (Collection)this.messageRepository.get(clientID);
		this.messageRepository.remove(clientID);
		return messages;
	}
}
